package ucn.dmf83.sc.workshop1.group3.ControlLayer;

import java.util.ArrayList;

import ucn.dmf83.sc.workshop1.group3.DomainLayer.*;

public class AddressBookCtrl {
	private AddressBook addressBook;
	
	public AddressBookCtrl() {
		addressBook = new AddressBook();
	}

	
	/*
	 * 
	 *   PERSON HANDLING
	 * 
	 */
	
	public void addPerson(String name, String address, String city, int postCode, String phone) {
		this.addressBook.addPerson(name, address, city, postCode, phone);
	}
	
	
	public ArrayList<Person> getPeople() {
		return this.addressBook.getPeople();
	}
	
	public ArrayList<Person> getPeople(String partialName) {
		return this.addressBook.getPeople(partialName);
	}
	
	public Person getPerson(int id) {
		return this.addressBook.getPerson(id);
	}
	
	public Person getPerson(String name) {
		return this.addressBook.getPerson(name);
	}
	
	public Person getPerson(String address, int postCode, String city) {
		return this.addressBook.getPerson(address, postCode, city);
	}
	
	public void removePerson(String address, String city, int postCode) {
		this.addressBook.removePerson(address, city, postCode);
	}
	
	public void editPerson(String address, int postCode, String city, String name, String nAddress, int nPostCode, String nCity, String nPhone) {
		this.addressBook.editPerson(getPerson(address, postCode,city), name, nAddress, nCity, nPostCode, nPhone);
	}
	
	/*
	 * 
	 *   DVD HANDLING
	 * 
	 */
	
	public void addDVD(String title, String publishDate) {
		this.addressBook.addDVD(title, publishDate);
	}
	
	public DVD getDVD(int id) {
		return this.addressBook.getDVD(id);
	}
	
	public DVD getDVD(String title) {
		return this.addressBook.getDVD(title);
	}
	
	public ArrayList<DVD> getDVDs() {
		return this.addressBook.getDVDs();
	}
	
	public ArrayList<DVD> getDVDs(String partialTitle) {
		return this.addressBook.getDVDs(partialTitle);
	}
	
	public void removeDVD(String title) {
		this.addressBook.removeDVD(title);
	}
	
	public void editDVD(String origTitle, String title, String publishDate) {
		this.addressBook.editDVD(this.addressBook.getDVD(origTitle), title, publishDate);
	}
	
	/*
	 * 
	 *   COPY HANDLING
	 * 
	 */
	
	public void addCopy(DVD dvd, String serialNum, String purchaseDate, double purchasePrice) {
		this.addressBook.addCopy(dvd, serialNum, purchaseDate, purchasePrice);
	}
	
	public ArrayList<Copy> getCopies(DVD dvd) {
		return this.addressBook.getCopies(dvd);
	}
	
	public ArrayList<Copy> getCopies(String title) {
		return this.addressBook.getCopies(title);
	}
	
	public Copy getCopy(String serialNum)
	{
		return this.addressBook.getCopy(serialNum);
	}
	
	public void removeCopy(String serialNum) {
		this.addressBook.removeCopy(serialNum);
	}
	
	public void editCopy(String serialNumOrig, String serialNum, String purchaseDate, double purchasePrice) {
		this.addressBook.editCopy(getCopy(serialNumOrig), serialNum, purchaseDate, purchasePrice);
	}
	

	/*
	 * 
	 *   LOAN HANDLING
	 * 
	 */
	
	public void addLoan(Person person, String borrowDate, int period, Copy copy) {
		this.addressBook.addLoan(person, borrowDate, period, copy);
	}
	
	public ArrayList<Loan> getLoans(Person person){
		return this.addressBook.getLoans(person);
	}
	
	public Loan getLoan(Person person, int id){
		return this.addressBook.getLoan(person, id);
	}
	
	public void returnLoan(Person person, int loanID) {
		if(person != null)
			this.addressBook.returnLoan(person, loanID);
		else
			System.out.println("The person doesn't exist!");
	}
}
